﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Hisuntech.SystemFramework.Net.Json;

public partial class _Default : System.Web.UI.Page 
{
    protected void Page_Load(object sender, EventArgs e)
    {
        decimal d = getValue<System.Decimal>("aaa");
    }

    T getValue<T>(string str)
    {
        return default(T);
    }
    protected void Button1_Click(object sender, EventArgs e)
    {


        ////复杂类型的请求
        //WCFService.CompositeType ct1 = new WCFService.CompositeType();
        //ct1.BoolValue = true;
        //ct1.StringValue = "AAA"+this.TextBox1 .Text ;
        //WCFService.CompositeType ct2 = new WCFService.CompositeType();
        //ct2.BoolValue = false ;
        //ct2.StringValue = "BBB";

        //GetCompositeType getct = new GetCompositeType(ct1, ct2);
       
        //List<WCFService.CompositeType> list = JSONClient.PostData<GetCompositeType, List<WCFService.CompositeType>>("http://localhost:9162/Service1.svc/DataContractList", getct);

        //this.Label1.Text = "获取列表成功！元素数量："+list .Count ;

        TestGetData();
    }

    void TestGetData()
    {
      
        string result = JSONClient.GetResultString("http://localhost:9162/Service1.svc/GetData?value=10");
       
        this.Label1.Text = result;
    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        //////MyFundService..FoundMarketClient market = new MyFundService.FoundMarketClient();
        ////////MyFundService.Model_FoundMarket [] list= market.GetFoundMarket();//已经使用JSON格式，会报错。
        //////string url = market.Endpoint.Address.Uri.ToString();
        //////market.Close();
       string  url = "http://localhost:9162/FundMarketService.svc/GetFoundMarket";

        //使用服务代理实体类，必须引用服务。
      //var list=JSONClient.GetData< List < MyFundService .Model_FoundMarket >>(url);
      //DateTime st1 = DateTime.Now;
      //for (int i = 0; i < 100; i++)
      //{
      //    foreach (MyFundService.Model_FoundMarket item in list)
      //    {
      //        decimal dayyield = item.dayyield;
      //        string bzdm = item.bzdm;
      //    }
      //}
     
      //System.Diagnostics.Debug.WriteLine("遍历集合(代理实体类)中所有的元素并取值(100次)，耗时（ms）："+DateTime .Now .Subtract (st1).TotalMilliseconds .ToString ());
      
        

        //使用本地实体类，好处是本地无需任何配置
      var list1=  JSONClient.GetData<List<NBFModel .Model_FoundMarket >>(url);
      
      DateTime st1 = DateTime.Now;
      for (int i = 0; i < 100; i++)
      {
          foreach (NBFModel.Model_FoundMarket item in list1)
          {
              decimal dayyield = item.dayyield;
              string bzdm = item.bzdm;
          }
      }
      

      System.Diagnostics.Debug.WriteLine("遍历集合(本地实体类)中所有的元素并取值(100次)，耗时（ms）：" + DateTime.Now.Subtract(st1).TotalMilliseconds.ToString());
      
      

    }
}

//[System.Runtime.Serialization.DataContract(Namespace = "http://schemas.datacontract.org/2004/07/")]
//[System.SerializableAttribute()]
//public class GetCompositeType
//{
//    [System.Runtime.Serialization.DataMember(Name = "ct1")]
//    public WCFService.CompositeType CT1{get;set;}

//    [System.Runtime.Serialization.DataMember(Name = "ct2")]
//    public WCFService.CompositeType CT2{get;set;}

//    public GetCompositeType(WCFService.CompositeType ct1, WCFService.CompositeType ct2)
//    {
//        this.CT1 = ct1;
//        this.CT2 = ct2;
//    }

//}

/*
 * 也可以这样定义要请求的类：
 *

[System.SerializableAttribute()]
public class GetCompositeType
{
    public WCFService.CompositeType ct1;//字段名称必须跟请求的方法参数名称一样。
    public WCFService.CompositeType ct2;

    public GetCompositeType(WCFService.CompositeType ct1, WCFService.CompositeType ct2)
    {
        this.CT1 = ct1;
        this.CT2 = ct2;
    }

}
 */
